#!/bin/bash

echo "Starting Japan Company CMS System..."
echo ""

# Check if Java is installed
if ! command -v java &> /dev/null; then
    echo "Error: Java is not installed"
    echo "Please install Java 17 or higher"
    exit 1
fi

# Check if Maven is installed
if ! command -v mvn &> /dev/null; then
    echo "Error: Maven is not installed"
    echo "Please install Maven"
    exit 1
fi

# Check if MySQL is running
echo "Checking MySQL connection..."
mysql -u root -p123456 -h localhost -e "USE japan_cms;" &> /dev/null
if [ $? -ne 0 ]; then
    echo "Warning: Cannot connect to MySQL database"
    echo "Please make sure MySQL is running and database 'japan_cms' exists"
    echo "Default credentials: root/123456"
    echo ""
fi

# Create uploads directory if not exists
mkdir -p uploads/images
mkdir -p uploads/files

echo "Starting Spring Boot application..."
echo "Application will be available at: http://localhost:8080"
echo "Database monitoring: http://localhost:8080/druid"
echo ""
echo "Press Ctrl+C to stop the application"
echo ""

# Run the application
mvn spring-boot:run